﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.Designer.Event.UI
{
    public class UIEventBus
    {
        private static object s_lockObj = new object();
        private static Common.EventBus s_instance;

        private static Common.EventBus Instance
        {
            get
            {
                if (s_instance == null)
                {
                    lock (s_lockObj)
                    {
                        if (s_instance == null)
                        {
                            s_instance = Common.EventBus.Create("EVENT_UI");
                        }
                    }
                }
                return s_instance;
            }
        }

        /// <summary>
        /// 注册接收者
        /// </summary>
        /// <param name="receiver"></param>
        public static void Register(object receiver)
        {
            Instance.Register(receiver);
        }

        /// <summary>
        /// 取消接收者的注册
        /// </summary>
        /// <param name="receiver"></param>
        public static void Unregister(object receiver)
        {
            Instance.Unregister(receiver);
        }

        /// <summary>
        /// 发布事件
        /// </summary>
        /// <param name="event"></param>
        public static void Publish(UIEvent @event)
        {
            Instance.Publish(@event);
        }

        /// <summary>
        /// 异步方式发布事件
        /// </summary>
        /// <param name="event"></param>
        public static void PublishAsync(UIEvent @event)
        {
            Instance.PublishAsync(@event);
        }
    }
}
